package edu.jd.movieplatform.user.ticket;

import edu.jd.movieplatform.common.CommonService;
import edu.jd.movieplatform.common.CurrentUser;
import edu.jd.movieplatform.common.Result;
import edu.jd.movieplatform.common.TokenUtils;
import edu.jd.movieplatform.user.ticket.impl.TicketServiceImpl;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/user/ticket")
public class TicketAPI {

    @Resource
    private TicketServiceImpl ticketService;

    @Resource
    private CommonService commonService;

    @PostMapping("/add-temp")
    public Result createTempTicket(@RequestBody Ticket_temp temp){
        ticketService.addTemp(temp);
        return Result.success("success");
    }

    @GetMapping("/get-temp")
    public Result getTempTicket(@RequestHeader("Token")String token){
        CurrentUser currentUser = TokenUtils.getUserInfo(token, commonService);
        List<Ticket_temp> temp = ticketService.getTemp(currentUser.getUserName());
        return Result.success("success", temp);
    }

    @PostMapping("/delete-temp")
    public Result deleteTempTicket(@RequestBody Ticket_temp temp){
        System.out.println(temp.getCust_username());
        ticketService.deleteTemp(temp);
        return Result.success("delete success");
    }

    @GetMapping("/delete-all-temp")
    public Result deleteAllTemp(@RequestHeader("Token")String token){
        CurrentUser currentUser = TokenUtils.getUserInfo(token, commonService);
        ticketService.deleteAllTemp(currentUser.getUserName());
        return Result.success("delete all temp ticket");
    }

    @GetMapping("/selected")
    public Result getSelectedSeat(SeatQueryDto seatQueryDto){
        List<SeatDto> selectedSeats = ticketService.getSelectedSeats(seatQueryDto);
        return Result.success("success", selectedSeats);
    }

    @GetMapping("/get-ticket")
    public Result getTickets(@RequestHeader("Token")String token){
        CurrentUser currentUser = TokenUtils.getUserInfo(token, commonService);
        List<Ticket> tickList = ticketService.getTickets(currentUser.getUserName());
        return Result.success("success", tickList);
    }
}
